<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    {include file="public/meta"}
    <!--/meta 作为公共模版分离出去-->
    <title>添加新章节</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
</head>
<body style="background-color:#fff">
<div class="wap-container">
    <div class="panel">
        <div class="panel-body">
            <form action="" method="post" class="form form-horizontal" id="form-member-add">
                <div class="row clearfix">
                    <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>章节标题：</label>
                    <div class="form-controls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" value="{$chapter.name}" placeholder="" id="chaptername" name="chaptername">
                    </div>
                </div>
                <input type="hidden" name="book_id" value="{$chapter.book_id}">
                <input type="hidden" name="chapter_id" value="{$chapter.id}">
                <input type="hidden" name="content_id" value="{$chapter.content_id}">
                <input type="hidden" name="words" id="words" value="{$chapter.size}">

                <div class="row clearfix">
                    <label class="form-label col-xs-4 col-sm-2">章节内容：</label>
                    <div class="form-controls col-xs-8 col-sm-9">
                        <textarea name="content" style="height:500px;" class="textarea" id="text_txt1">{$content.content}</textarea>
                        <span id ="num_txt1">已经输入{$chapter.size}字</span>
                    </div>
                </div>

                <div class="row clearfix">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
{include file="public/footer"}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/author/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/static/author/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/static/author/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-member-add").validate({
            rules:{
                chaptername:{
                    required:true,
                },

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{:url('edit')}" ,
                    success: function(data){
                        // console.log(data);
                        if(data.state == 200){
                            layer.msg("修改成功",{icon:1,time:1500},function(){
                                parent.window.location.href="/author/my_book/index/book_id/{$chapter.book_id}";
                                var index=parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg("修改失败",{icon:1,time:1500});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:1,time:1000});
                    }
                });
            }
        });
    });
</script>
<script>
    $(function(){
        $('#text_txt1').on('keyup',function(){
            var txtval = $('#text_txt1').val().length;
            $('#num_txt1').html('已经输入'+txtval+'字');
            $('#words').val(txtval);
            // console.log(txtval);
            // var str = parseInt(600-txtval);
            // console.log(str);
            // if(str > 0 ){
            //     $('#num_txt1').html('剩余可输入'+str+'字');
            // }else{
            //     $('#num_txt1').html('剩余可输入0字');
            //     $('#text_txt1').val($('#text_txt1').val().substring(0,600)); //这里意思是当里面的文字小于等于0的时候，那么字数不能再增加，只能是600个字
            // }
            //console.log($('#num_txt').html(str));
        });
    })
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
